<?php
require_once('../../config/config.inc');
header('Content-Type: text/html; charset=utf-8');
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
	die('Failed to connect to server: ' . mysql_error());
}

//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
	die("Unable to select database");
}
$select = mysql_query("SELECT * FROM books WHERE id='".$_GET['id']."'");
$row= mysql_fetch_array($select);
$filename=$row['filename'];
$imgname=$row['imgname'];

$qry = mysql_query("DELETE FROM `books` WHERE id='".$_GET['id']."'");
if($qry){
	$filedelete=unlink("../upload_file/".$filename);
	$imgdelete=unlink("../upload_img/".$imgname);
	if($filedelete && $imgdelete){
	header("Location: ../index.php#collapseFour");
	}
}
else{
	echo mysql_error();
}